<template>
  <div class="home-container">
    <van-nav-bar fixed>
      <!-- 右侧 的插槽-->
      <template #right>
        <van-icon name="search" size="18" />
      </template>
      <!-- 左侧 -->
      <template #left>
        <img src="../../assets/toutiao_logo.png" class="logn" alt="" />
      </template>
    </van-nav-bar>
    <!-- 列表区域 -->
    <van-tabs v-model="active" sticky offset-top="1.22667rem">
      <van-tab :title="item.name" v-for="item in channels" :key="item.id">
        <!-- {{ item.name }}--{{ item.id }}} -->
        <ArtList :channel-id="item.id"></ArtList>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import { getUserChannelsAPI } from '@/api/homeAPI.js'
import ArtList from '@/components/ArtList/ArtList.vue'

export default {
  components: {
    ArtList
  },
  name: 'Home',
  data () {
    return {
      active: 0,
      channels: []
    }
  },
  created () {
    this.initUserChannels()
  },
  methods: {
    async initUserChannels () {
      const { data: res } = await getUserChannelsAPI()
      console.log(res)
      if (res.message === 'OK') {
        // 把拿到的数据转存到模板中
        this.channels = res.data.channels
      }
    }
  }
}
</script>

<style lang="less" scoped>
.logn {
  height: 80%;
}
.home-container {
  padding-top: 46px;
  padding-bottom: 50px;
}
</style>
